package com.jt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jt.mapper.AccountSMapper;
import com.jt.pojo.Account;
import com.jt.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl extends ServiceImpl<AccountSMapper, Account> implements AccountService {

    @Autowired
    private AccountSMapper accountSMapper;


    @Override
    public boolean deleteAccount(String userId, BigDecimal money) {

        Account account = accountSMapper.selectOne(new QueryWrapper<Account>().eq("userId", userId));
        BigDecimal number = account.getNumber();
        account.setNumber(number.subtract(money));
        int userId1 = accountSMapper.update(account, new QueryWrapper<Account>().eq("userId", userId));
        if (userId1 > 0) {
            return true;
        }
        return false;
    }
}
